//
//  HXDTextAttachment.swift
//  weibo
//
//  Created by huxuedong on 15/12/17.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

import UIKit

class HXDTextAttachment: NSTextAttachment {
    
    var emoticon: HXDEmoticon?
    
    func attributeStringWithEmoticon(emoticon: HXDEmoticon, font: UIFont) -> NSAttributedString {
        self.emoticon = emoticon
        //根据路径获取表情图片
        let emoticonImage = UIImage(named: emoticon.fullPath!, inBundle: HXDEmoticonTools.sharedInstance.emoticonBundel, compatibleWithTraitCollection: nil)
        //设置文本附件的图片
        self.image = emoticonImage
        //获取文字行高
        let textHeight = font.lineHeight
        //设置附件的大小
        bounds = CGRect(x: 0, y: -3.5, width: textHeight, height: textHeight)
        return NSAttributedString(attachment: self)
    }

}
